package com.wn.androidflutterinnerwndemo

import android.app.Application
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.FlutterEngineCache
import io.flutter.embedding.engine.dart.DartExecutor

/**
 * Author : wn
 * Email : maoning20080808@163.com
 * Date : 2025/7/19 11:10
 * Description :
 */
class MyApp : Application() {

    // 声明一个 FlutterEngine
    lateinit var flutterEngine: FlutterEngine

    override fun onCreate() {
        super.onCreate()

        initEngine1()
        initEngine2()
    }

    private fun initEngine1(){
        // 预初始化 Flutter 引擎
        flutterEngine = FlutterEngine(this)

        // 可选：设置初始路由 - 如果只有1个，默认是main.dart
        //flutterEngine.navigationChannel.setInitialRoute("/");
        flutterEngine.navigationChannel.setInitialRoute("/main");

        // 预执行 Dart 代码（可选，可以提前预热引擎）
        flutterEngine.dartExecutor.executeDartEntrypoint(
            DartExecutor.DartEntrypoint.createDefault()
        )

        // 预编译和缓存 Flutter 引擎（可选）
        FlutterEngineCache.getInstance().put("wn_engine_id", flutterEngine)
    }

    private fun initEngine2(){
        // 预初始化 Flutter 引擎
        val flutterEngine = FlutterEngine(this)

        // 可选：设置初始路由
        flutterEngine.navigationChannel.setInitialRoute("/mutual_communication")

        // 预执行 Dart 代码（可选，可以提前预热引擎）
        flutterEngine.dartExecutor.executeDartEntrypoint(
            DartExecutor.DartEntrypoint.createDefault()
        )

        // 预编译和缓存 Flutter 引擎（可选）
        FlutterEngineCache.getInstance().put("mutual_communication_engine_id", flutterEngine)
    }
}